package com.happyfamily.springboot.crowdsourcingplatform.dao.sun;

import com.happyfamily.springboot.crowdsourcingplatform.model.Need;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NedDao
{
	//我要投标获取需求集合，审核状态必须为已审核，投标状态必须为未中标，截止投标日期为今天以后
	@Select("<script> SELECT * FROM need " +
			"WHERE nstatus='已审核' AND nstate='未中标'" +
			" <when test='acc!=null'> AND nuseraccount LIKE CONCAT ('%',#{acc},'%')</when>" +
			"<when test='sname!=null'> AND sname=#{sname}</when> " +
			"ORDER BY nendtime LIMIT #{start} OFFSET #{end}</script>")
	public abstract List<Need> getList(Integer start, Integer end, String acc,String sname);


	//我要投标获取需求总数
	@Select("<script> SELECT COUNT(*) FROM need " +
			"WHERE nstatus='已审核' AND nstate='未中标'" +
			" <when test='acc!=null'> AND nuseraccount LIKE CONCAT ('%',#{acc},'%')</when>" +
			"<when test='sname!=null'> AND sname=#{sname}</when> </script>")
	public abstract int getSum(String acc,String sname);

	//根据id查询某个需求
	@Select("SELECT * FROM need WHERE nid=#{nid}")
	public abstract Need getNeed(Long nid);
}